package com.xinshujia.config.authentication.handler;

import com.xinshujia.response.RespResult;
import com.xinshujia.utils.HttpServletResponseUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author: 野狼上校
 * @create: 2023-05-30  22:31
 * @version: 1.0
 * @description: 认证失败处理器
 */
@Component
public class MyAuthenticationFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
        HttpServletResponseUtil httpServletResponseUtil = new HttpServletResponseUtil();
        RespResult result = RespResult.Fail("登录失败,手机号码或密码错误");
        httpServletResponseUtil.responseAuthenticationResult(response,result);
    }
}